package ewgenius.xube.engine;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;

public class InputState {
	public InputState() throws LWJGLException {
		Keyboard.create();
		Mouse.create();
		
		mouseButtonsCount = Mouse.getButtonCount();
		mouseButton = new boolean[mouseButtonsCount];
	}
	
	private int mouseButtonsCount = 0;
	
	public boolean keyUp = false;
	public boolean keyDown = false;
	public boolean keyLeft = false;
	public boolean keyRight = false;
	public boolean keyShift = false;
	public boolean keyCtrl = false;
	public boolean keyEsc = false;
	public boolean keyP = false;
	public boolean keyF1 = false;
	public boolean keyF2 = false;
	public boolean keyF3 = false;
	public boolean keyF4 = false;
	
	public float mouseSensitivity = 0.001f;
	public float mouseX = 0f;
	public float mouseY = 0f;
	public float mouseDX = 0.0f;
	public float mouseDY = 0.0f;
	public float mouseDScroll = 0.0f;
	public boolean[] mouseButton;
	public boolean mouseIsDragging = false;

	public void update() {
		keyUp = Keyboard.isKeyDown(Keyboard.KEY_UP);
		keyShift = Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
		keyCtrl = Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
		keyDown = Keyboard.isKeyDown(Keyboard.KEY_DOWN);
		keyLeft = Keyboard.isKeyDown(Keyboard.KEY_LEFT);
		keyRight = Keyboard.isKeyDown(Keyboard.KEY_RIGHT);
		keyEsc = Keyboard.isKeyDown(Keyboard.KEY_ESCAPE);
		keyP = Keyboard.isKeyDown(Keyboard.KEY_P);
		keyF1 = Keyboard.isKeyDown(Keyboard.KEY_F1);
		keyF2 = Keyboard.isKeyDown(Keyboard.KEY_F2);
		keyF3 = Keyboard.isKeyDown(Keyboard.KEY_F3);
		keyF4 = Keyboard.isKeyDown(Keyboard.KEY_F4);
		
		
		mouseX = Mouse.getX();
		mouseY = Mouse.getY();
		mouseDX = Mouse.getDX();// - mouseDX;
		mouseDY = Mouse.getDY();// - mouseDY;
		
		for(int i=0;i<mouseButtonsCount;i++)
			mouseButton[i] = Mouse.isButtonDown(i);
	}
	
	public boolean checkMouseInArea(int x1, int y1, int x2, int y2) {
		if(mouseX >= x1 && mouseX <= x2 && mouseY >= y1 && mouseY <= y2)
			return true;
		else
			return false;
	}
}
